function parse(strArr = []) {
  let opArr = [], numberArr = [];

  while (strArr.length > 0) {
    // 从右往左解析
    const token = strArr.pop();
    
    if (isNumber(token)) {
      const numArr = [token];
      // 如果当前是数字，那么需要一直取数，一直到不是数字为止
      while (isNumber(strArr[strArr.length - 1])) {
        numArr.push(strArr.pop());
      }

      if (isTimesOrDivision(opArr[opArr.length - 1])) {
        const res = caculator(numArr.join(""), opArr.pop(), numberArr.pop());

        numberArr.push(res);
        // 计算值
      } else {
        numberArr.push(numArr.join(""));
      }
      continue;
    }

    if (isSubQuote(token)) {
      if (token === "(") {
        // 因为是从右往左，所以遇到 ( 时代表子表达式结束
        return caculator(numberArr.pop(), opArr.pop(), numberArr.pop())
      } else {
        const res = parse(strArr, true);
        numberArr.push(res);
      }
      continue;
    }

    if (isSubtractionOrAddition(token)) {
      if (
        isTimesOrDivision(opArr[opArr.length - 1]) ||
        isSubtractionOrAddition(opArr[opArr.length - 1])
      ) {
        // 如果之前也是运算符，那么就要计算值
        const res = caculator(numberArr.pop(), opArr.pop(), numberArr.pop());
        numberArr.push(res);
      }

      opArr.push(token);
      continue;
    }

    if (isTimesOrDivision(token)) {
      if (isTimesOrDivision(opArr[opArr.length - 1])) {
        // 如果之前也是 * / 操作符，那么就要计算值
        const res = caculator(numberArr.pop(), opArr.pop(), numberArr.pop());
        numberArr.push(res);
      }
      opArr.push(token);
      continue;
    }
  }

  return caculator(numberArr.pop(), opArr.pop(), numberArr.pop());
}

const str = "1 + 3 * (1 - 2)";
console.log(parse(str.split("")));

function isNumber(str) {
  return !isNaN(parseFloat(str));
}

/**
 * 是否+ - 号
 * @param {string} str
 * @returns boolean
 */
function isSubtractionOrAddition(str) {
  return str === "+" || str === "-";
}

function isTimesOrDivision(str) {
  return str === "*" || str === "/";
}

function isSubQuote(str) {
  return str === "(" || str === ")";
}

function caculator(left, op, right) {
  left = parseFloat(left);
  right = parseFloat(right);

  switch (op) {
    case "+":
      return left + right;
    case "-":
      return left - right;
    case "*":
      return left * right;
    case "/":
      return left / right;
    default:
      throw new Error(`unexpect op:${op}, left:${left}, right:${right}`);
  }
}


console.log(eval('1+2+3+4+5 + 6 * (7 - 8 * 10 -10 +1000) * 200'))